package com.app.lxx.pregnancyberth.ui.adapter;

import android.graphics.Color;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.app.lxx.pregnancyberth.R;
import com.app.lxx.pregnancyberth.ui.entity.UserInfoEntity;

import java.util.List;

/**
 * Created by Lxx on PregnancyBerth
 * 2019/9/4 17:12 星期三
 */

public class HomeNoteAdapter extends RecyclerView.Adapter {

    private int TYPE_PT = 1, TYPE_LB = 2;

    private List<UserInfoEntity.DataBean.MaternalBean.ShowItemsBean> listBeans;

    public HomeNoteAdapter(List<UserInfoEntity.DataBean.MaternalBean.ShowItemsBean> listBeans) {
        this.listBeans = listBeans;
    }

    private OnClickItemListener onClickItemListener;

    public interface OnClickItemListener {
        void onClickListener(int position);
    }

    public void setOnClickListener(OnClickItemListener clickListener) {
        onClickItemListener = clickListener;
    }


    @Override
    public int getItemViewType(int position) {
        if (position != 5) {
            return TYPE_PT;
        } else {
            return TYPE_LB;
        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        View view;
        if (viewType == TYPE_PT) {
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_userinfo_pt_layout, viewGroup, false);
            return new MyViewHolderPt(view);
        } else {
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_userinfo_lb_layout, viewGroup, false);
            return new MyRecmendViewHolder(view);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int position) {
        UserInfoEntity.DataBean.MaternalBean.ShowItemsBean showItemsBean = listBeans.get(position);
        if (viewHolder instanceof MyViewHolderPt) {

        } else if (viewHolder instanceof MyViewHolderLb) {

        }

        // List<String> keys = new ArrayList<>(stringStringHashMap.keySet());
        //  Gson gson = new Gson();
        //  Type type = new TypeToken<List<User>>() {
        //  }.getType();
        //  List<User> list = gson.fromJson(responseData, type);
    //  String title = showItemsBean.getTitle();
    //  if (title.length() > 6) {
    //      holder.setText(R.id.userinfo_title, title.substring(0, 6) + "：");
    //  } else {
    //      holder.setText(R.id.userinfo_title, title + "：");
    //  }
    //  MarqueeView marqueeView = holder.getView(R.id.marqueeView);
    //  marqueeView.stopFlipping();
    //  marqueeView.startWithText(showItemsBean.getValue());

    //  View userinfoly = holder.getView(R.id.userinfoly);
    //  =showItemsBean.getColor();

    }

    private void setBackColor(View userinfoly, String color) {
        if (!TextUtils.isEmpty(color)) {
            String extend = "#" + color;
            userinfoly.setBackgroundColor(Color.parseColor(extend));
        }
    }

    @Override
    public int getItemCount() {
        return listBeans.size();
    }

    private class MyRecmendViewHolder extends RecyclerView.ViewHolder {
        public MyRecmendViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }

    private class MyViewHolderPt extends RecyclerView.ViewHolder {

        LinearLayout userinfoly;
        TextView userinfo_title;

        public MyViewHolderPt(@NonNull View itemView) {
            super(itemView);

        }
    }

    private class MyViewHolderLb extends RecyclerView.ViewHolder {


        public MyViewHolderLb(@NonNull View itemView) {
            super(itemView);

        }
    }

    private class MyViewHolderWl extends RecyclerView.ViewHolder {

        public MyViewHolderWl(@NonNull View itemView) {
            super(itemView);

        }
    }

    private class MyViewHolderDs extends RecyclerView.ViewHolder {

        public MyViewHolderDs(@NonNull View itemView) {
            super(itemView);

        }
    }

    private class MyViewHolderDg extends RecyclerView.ViewHolder {

        public MyViewHolderDg(@NonNull View itemView) {
            super(itemView);

        }
    }

    private class MyViewHolderXf extends RecyclerView.ViewHolder {

        public MyViewHolderXf(@NonNull View itemView) {
            super(itemView);

        }
    }
}
